<?php


defined("IN_IA") || exit("Access Denied");
require "inc/func/core.php";
/**
 * -微圈小程序模块微站定义
 *
 * @author 厦门科技
 * @url 
 */
class yzzc_sunModuleSite extends Core
{
	public function doWebNotify($data)
	{
		global $_W;
		global $_GPC;
		$attach = $data["attach"];
        $return_code = $data['return_code'];
        if ($return_code != 'SUCCESS'){
            exit("FAIL");
        }
		if ($attach) {
			$attach_arr = explode("@@@", $attach);
			if (sizeof($attach_arr) == 3) {
				$_W["uniacid"] = $uniacid = intval($attach_arr[0]);
				$ordertype = intval($attach_arr[1]);
				$oid = intval($attach_arr[2]);
			} else {
				exit("FAIL");
			}
		} else {
            $_W["uniacid"] = $_GPC['uniacid'];
            $ordertype = $_GPC['type'];
            $oid = $_GPC['order_id'];
		}
		if ($ordertype == 0) {
            //租聘订单
            $total_fee = $data['total_fee'] / 100 ;
            $orderget = pdo_get("yzzc_sun_order", ["uniacid" => $_W["uniacid"], "id" => $oid, "status" => 1]);
			if ($orderget) {
                $zlsz = pdo_get("yzzc_sun_order_set", ["uniacid" => $_W["uniacid"]], ["zlsz",'shuttle_type','shuttle_commission']);
                //计算交还车原收益
                $shuttle_commission = 0;
                if ($zlsz['shuttle_type'] == 1){
                    //订单总额百分比
                    $shuttle_commission =  round(($zlsz['shuttle_commission'] / 100) * $orderget['prepay_money'],2);
                }
                if ($zlsz['shuttle_type'] == 2){
                    //订单总额固定值
                    $shuttle_commission = $zlsz['shuttle_commission'];
//                    if ($zlsz['shuttle_commission'] >= $orderget['prepay_money']){
//                        $shuttle_commission = $orderget['prepay_money'];
//                    }
                }

                //更新订单状态
				$res = pdo_update("yzzc_sun_order", [
                    "ispay" => 1,
                    "paytime" => time(),
                    "status" => 2,
                    'prepay_money' => $total_fee,
                    'shuttle_commission' => $shuttle_commission
                ], ["uniacid" => $_W["uniacid"], "id" => $oid]);

                //更新订单时间
                $data1 = [
                    'start_time' => $orderget["start_time"],
                    'end_time' => $orderget["end_time"],
                    'carnum' => $orderget["carnum"],
                    'order_id' => $oid,
                    'goods_id' => $orderget['cid'],
                    'sku_id' => $orderget["sku_id"],
                    'uniacid' => $_W["uniacid"]
                ];
				pdo_insert("yzzc_sun_ordertime", $data1);
                $shop = pdo_get("yzzc_sun_branch", ["uniacid" => $_W["uniacid"], "id" => $orderget["start_shop"]]);

                //更新优惠劵
                if ($orderget['coupon'] > 0){
                    pdo_update("yzzc_sun_coupon_get", array("isuse" => 1, "usetime" => time()), array("cid" => $orderget['coupon'], "uid" => $orderget['uid']));
                }

                //创建商家结算费用
                $shop = pdo_get("yzzc_sun_branch", ["uniacid" => $_W["uniacid"], "id" => $orderget["start_shop"]]);
                $platform_fee = round($orderget['prepay_money'] * ($shop['platform_fee'] / 100),2);
                $income = [
                    'type' => $shop['type'],
                    'branch_id' => $shop['id'],
                    'uniacid' => $shop['uniacid'],
                    'order_id' => $orderget['id'],
                    'total' => $orderget['prepay_money'],
                    'platform_fee' => $platform_fee,
                    'amount' => $orderget['prepay_money'] - $platform_fee,
                    'createtime' => time(),
                ];
                pdo_insert('yzzc_sun_branch_income',$income);

                //
                //修改sku车辆状态
                pdo_update('yzzc_sun_goods_sku',['status'=>2],['id'=>$orderget['sku_id'],"uniacid" => $_W["uniacid"]]);

                //判断租聘方式，1，显示已租车辆，2 下架已租车辆
				if ($zlsz["zlsz"] == 0) {
                    //所有车辆都租完就下架
                    $sku_count = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_order_sku") . "where status = 1  and uniacid = {$_W["uniacid"]} and goods_id = {$oid}") ?? 0;
                    if ($sku_count <= 0){
                        pdo_update("yzzc_sun_goods", ["status" => 2], ["uniacid" => $_W["uniacid"], "carnum" => $orderget["carnum"]]);
                    }
				}

                //获取短信配置，发生租车短信
				$set = pdo_get("yzzc_sun_msg_set", ["uniacid" => $_W["uniacid"]]);
				if ($set["open"] == 1) {
					$mobile = $shop["shop_tel"];
                    include_once IA_ROOT . "/addons/yzzc_sun/api/TencentCloud/sendSms.php";
                    set_time_limit(0);
                    $sendid = $set["dayu_templatecode"];
                    if ($sendid != "") {
                        sendSms($set["dayu_accesskey"], $set["dayu_accesskeysecret"], $mobile, $set["dayu_signname"], $sendid);
                    }
				}

                //消费得积分积分
				$integral = pdo_get("yzzc_sun_integralset", ["uniacid" => $_W["uniacid"]], ["full", "cost_score"]);
				if ($integral["cost_score"] > 0) {
					$fanscore = floor($orderget["total_money"] * $integral["cost_score"] / $integral["full"]);
					$this->scoreAct($orderget["uid"], 3, $fanscore);
				}
				if ($res) {
					exit("SUCCESS");
				} else {
					exit("FAIL");
				}
			} else {
				exit("FAIL");
			}
			exit("SUCCESS");
		}
        elseif ($ordertype == 1) {
            //续租订单
			$orderget = pdo_get("yzzc_sun_xzorder", ["uniacid" => $_W["uniacid"], "id" => $oid, "ispay" => 0]);
			if ($orderget) {
				$res = pdo_update("yzzc_sun_xzorder", ["ispay" => 1, "paytime" => time()], ["uniacid" => $_W["uniacid"], "id" => $oid]);
				pdo_update("yzzc_sun_order", ["iszx" => 1, "xzmoney" => $orderget["total_money"], "xzday" => $orderget["day"], "xztime" => $orderget["end_time"]], ["uniacid" => $_W["uniacid"], "ordernum" => $orderget["ordernum"]]);
				$order = pdo_get("yzzc_sun_order", ["uniacid" => $_W["uniacid"], "ordernum" => $orderget["ordernum"]], ["carnum"]);
				$data1["start_time"] = $orderget["start_time"];
				$data1["end_time"] = $orderget["end_time"];
				$data1["carnum"] = $order["carnum"];
				$data1["uniacid"] = $_W["uniacid"];
				pdo_insert("yzzc_sun_ordertime", $data1);
				$integral = pdo_get("yzzc_sun_integralset", ["uniacid" => $_W["uniacid"]], ["full", "cost_score"]);
				if ($integral["cost_score"] > 0) {
					$fanscore = floor($orderget["total_money"] * $integral["cost_score"] / $integral["full"]);
					$this->scoreAct($orderget["uid"], 3, $fanscore);
				}
				if ($res) {
					exit("SUCCESS");
				} else {
					exit("FAIL");
				}
			} else {
				exit("FAIL");
			}
			exit("SUCCESS");
		}
        elseif ($ordertype == 2){
            //商家入驻订单
            $order = pdo_get("yzzc_sun_store_order", ["uniacid" => $_W["uniacid"], "order_id" => $oid, "pay_status" => 0]);
            if ($order){
                $res = pdo_update("yzzc_sun_store_order", ['pay_status' => 1,'updatetime'=>time()],["uniacid" => $_W["uniacid"], "order_id" => $oid]);
                if ($res) {
                    exit("SUCCESS");
                } else {
                    exit("FAIL");
                }
            }
        }
        elseif ($ordertype == 3){
            //商家会员套餐订单
            $order = pdo_get("yzzc_sun_store_order", ["uniacid" => $_W["uniacid"], "order_id" => $oid, "pay_status" => 0]);
            if ($order){
                $res = pdo_update("yzzc_sun_store_order", ['pay_status' => 1,'updatetime'=>time()],["uniacid" => $_W["uniacid"], "order_id" => $oid]);
                //更新商家数据
                $branch_info = pdo_get('yzzc_sun_branch',["uniacid" => $_W["uniacid"], "store_id" => $order['store_id']]);
                $store_edit = [];

                if ($branch_info['member_status'] == 0 || $branch_info['member_status'] == 2){
                    //开通会员，或者已过期
                    $store_edit = [
                        'member_status' => 1,
                        'member_start_time' => time(),
                        'member_end_time' => time() + ($order['member_month'] * (86400 * 30)),
                    ];
                }elseif ($branch_info['member_status'] == 1){
                    $store_edit = [
                        'member_end_time' => $branch_info['member_end_time'] + ($order['member_month'] * (86400 * 30))
                    ];
                }
                if ($store_edit){
                    //修改商家会员状态
                    pdo_update("yzzc_sun_branch", $store_edit, ["uniacid" => $_W["uniacid"], "store_id" => $order['store_id']]);
                }
                if ($res) {
                    exit("SUCCESS");
                } else {
                    exit("FAIL");
                }
            }
        }
        elseif ($ordertype == 4){
            //开票支付订单
            $order = pdo_get("yzzc_sun_store_order", ["uniacid" => $_W["uniacid"], "order_id" => $oid, "pay_status" => 0]);
            if ($order){
                $res = pdo_update("yzzc_sun_store_order", ['invoice_pay_status' => 1,'invoice_pay_time'=>time()],["uniacid" => $_W["uniacid"], "order_id" => $oid]);
                if ($res) {
                    exit("SUCCESS");
                } else {
                    exit("FAIL");
                }
            }
        }
	}

    public function doWebFddNotify($data)
    {
        $data = json_decode(html_entity_decode($this->request->post('bizContent')), true);

        if ($this->request->header('x-fasc-app-id') != Request::APPID) {
            return json(['msg' => 'fail']);
        }

        $waitHandleEvent = ['sign-task-finished', 'user-authorize'];

        if (!in_array($this->request->header('x-fasc-event'), $waitHandleEvent)) {
            return json(['msg' => 'success']);
        }

        switch ($this->request->header('x-fasc-event')) {
            case 'sign-task-finished':
                $apply = Db::name('apply')->where('task_id', $data['signTaskId'])->find();
                // 2 签约中
                if (!$apply || $apply['status'] != 2) {
                    return json(['msg' => 'fail']);
                }

                // 3 已签约
                Db::name('apply')->where('id', $apply['id'])->update([
                    'status' => 3
                ]);
                break;
            case 'user-authorize':
                Log::write($data, 'error');
                if ($data['authResult'] != 'success') {
                    return json(['msg' => 'fail']);
                }

                Db::name('user')->where('id', $data['clientUserId'])->update([
                    'fdd_id' => $data['openUserId']
                ]);
        }

        return json(['msg' => 'success']);
    }
    function CheckSku($goods_id,$start_time,$end_time)
    {
        global $_W;
        $stime = $start_time;
        $etime = $end_time;

        $order = pdo_fetch("select id from " . tablename("yzzc_sun_order") . " where uniacid = " . $_W["uniacid"] . " and cid = '{$goods_id}' and (status = 2 or status = 3)");

        $result = false;
        if (!$order) {
            $allorder = pdo_fetchall("select * from " . tablename("yzzc_sun_ordertime") . " where uniacid = " . $_W["uniacid"] . " and goods_id = '{$goods_id}'");
            if (!$allorder){
                return true;
            }
            foreach ($allorder as $key => $value) {
                $start_time = $value["start_time"];
                $end_time = $value["end_time"];
                if ($stime <= $start_time && $etime >= $end_time && $start_time <= $etime && $stime <= $end_time) {
                    continue;
                } else {
                    if ($stime <= $start_time && $end_time >= $etime && $start_time <= $etime && $stime <= $end_time) {
                        continue;
                    } else {
                        if ($start_time <= $stime && $etime >= $end_time && $start_time <= $etime && $stime <= $end_time) {
                            continue;
                        } else {
                            if ($start_time <= $stime && $end_time >= $etime && $start_time <= $etime && $stime <= $end_time) {
                                continue;
                            } else {
                                $result = true;
                                break;
                            }
                        }
                    }
                }
            }
            return $result;
            //$this->return_msg(1, array(), "首次下单");
        } else {
            $allorder = pdo_fetchall("select * from " . tablename("yzzc_sun_ordertime") . " where uniacid = " . $_W["uniacid"] . " and goods_id = {$goods_id}");
            if (!$allorder){
                return true;
            }
            foreach ($allorder as $key => $value) {
                $start_time = $value["start_time"];
                $end_time = $value["end_time"];
                if ($stime <= $start_time && $etime >= $end_time && $start_time <= $etime && $stime <= $end_time) {
                    continue;
                } else {
                    if ($stime <= $start_time && $end_time >= $etime && $start_time <= $etime && $stime <= $end_time) {
                        continue;
                    } else {
                        if ($start_time <= $stime && $etime >= $end_time && $start_time <= $etime && $stime <= $end_time) {
                            continue;
                        } else {
                            if ($start_time <= $stime && $end_time >= $etime && $start_time <= $etime && $stime <= $end_time) {
                                continue;
                            } else {
                                $result = true;
                                break;
                            }
                        }
                    }
                }
            }
            return $result;
        }
    }
	public function doWebTest()
	{
		global $_W;
		global $_GPC;
		$oid = $_GPC["oid"];
		$this->result(0, $_W["current_module"]["name"]);
		$attach["attach"] = $_W["uniacid"] . "@@@0@@@" . $oid;
		$this->doWebNotify2($attach);
	}
	public function doWebTest2()
	{
		global $_W;
		global $_GPC;
		$oid = $_GPC["oid"];
		$this->result(0, $_W["current_module"]["name"]);
		$attach["attach"] = $_W["uniacid"] . "@@@1@@@" . $oid;
		$this->doWebNotify2($attach);
	}
	public function doWebNotify2($data)
	{
		global $_W;
		global $_GPC;
		$attach = $data["attach"];
		if ($attach) {
			$attach_arr = explode("@@@", $attach);
			var_dump($attach_arr);
			if (sizeof($attach_arr) == 3) {
				$_W["uniacid"] = $uniacid = intval($attach_arr[0]);
				$ordertype = intval($attach_arr[1]);
				$oid = intval($attach_arr[2]);
			} else {
				exit("FAIL170");
			}
		} else {
			exit("FAIL173");
		}
		if ($ordertype == 0) {
			$orderget = pdo_get("yzzc_sun_order", ["uniacid" => $_W["uniacid"], "id" => $oid, "status" => 1]);
			if ($orderget) {
				$res = pdo_update("yzzc_sun_order", ["ispay" => 1, "paytime" => time(), "status" => 2], ["uniacid" => $_W["uniacid"], "id" => $oid]);
				$data1["start_time"] = $orderget["start_time"];
				$data1["end_time"] = $orderget["end_time"];
				$data1["carnum"] = $orderget["carnum"];
				$data1["uniacid"] = $_W["uniacid"];
				pdo_insert("yzzc_sun_ordertime", $data1);
				$zlsz = pdo_get("yzzc_sun_order_set", ["uniacid" => $_W["uniacid"]], ["zlsz"]);
				if ($zlsz["zlsz"] == 0) {
					pdo_update("yzzc_sun_goods", ["status" => 2], ["uniacid" => $_W["uniacid"], "carnum" => $orderget["carnum"]]);
				}
				$set = pdo_get("yzzc_sun_msg_set", ["uniacid" => $_W["uniacid"]]);
				if ($set["open"] == 1) {
					$shop = pdo_get("yzzc_sun_branch", ["uniacid" => $_W["uniacid"], "id" => $orderget["start_shop"]]);
					$mobile = $shop["shop_tel"];
					if ($set["type"] == 1) {
						$this->SendYtxSms($set["buy_template"], $set, $mobile);
					} elseif ($set["type"] == 2) {
						include_once IA_ROOT . "/addons/yzzc_sun/api/aliyun-dysms/sendSms.php";
						set_time_limit(0);
						header("Content-Type: text/plain; charset=utf-8");
						$sendid = $set["dayu_templatecode"];
						if ($sendid != "") {
							$return = sendSms($set["dayu_accesskey"], $set["dayu_accesskeysecret"], $mobile, $set["dayu_signname"], $sendid);
						}
					}
				}
				$integral = pdo_get("yzzc_sun_integralset", ["uniacid" => $_W["uniacid"]], ["full", "cost_score"]);
				if ($integral["cost_score"] > 0) {
					$fanscore = floor($orderget["total_money"] * $integral["cost_score"] / $integral["full"]);
					$this->scoreAct($orderget["uid"], 3, $fanscore);
				}
				if ($res) {
					exit("SUCCESS");
				} else {
					exit("FAIL222");
				}
			} else {
				exit("FAIL225");
			}
			exit("SUCCESS");
		} elseif ($ordertype == 1) {
			$orderget = pdo_get("yzzc_sun_xzorder", ["uniacid" => $_W["uniacid"], "id" => $oid, "ispay" => 0]);
			echo json_encode($orderget);
			if ($orderget) {
				$res = pdo_update("yzzc_sun_xzorder", ["ispay" => 1, "paytime" => time()], ["uniacid" => $_W["uniacid"], "id" => $oid]);
				pdo_update("yzzc_sun_order", ["iszx" => 1, "xzmoney" => $orderget["total_money"], "xzday" => $orderget["day"], "xztime" => $orderget["end_time"]], ["uniacid" => $_W["uniacid"], "ordernum" => $orderget["ordernum"]]);
				$order = pdo_get("yzzc_sun_order", ["uniacid" => $_W["uniacid"], "ordernum" => $orderget["ordernum"]], ["carnum"]);
				$data1["start_time"] = $orderget["start_time"];
				$data1["end_time"] = $orderget["end_time"];
				$data1["carnum"] = $order["carnum"];
				$data1["uniacid"] = $_W["uniacid"];
				pdo_insert("yzzc_sun_ordertime", $data1);
				$integral = pdo_get("yzzc_sun_integralset", ["uniacid" => $_W["uniacid"]], ["full", "cost_score"]);
				if ($integral["cost_score"] > 0) {
					$fanscore = floor($orderget["total_money"] * $integral["cost_score"] / $integral["full"]);
					$this->scoreAct($orderget["uid"], 3, $fanscore);
				}
				if ($res) {
					exit("SUCCESS");
				} else {
					exit("FAIL");
				}
			} else {
				exit("FAIL");
			}
			exit("SUCCESS");
		}
	}
	public function SendYtxSms($msg, $sms = [], $mobile = "")
	{
		$postArr = ["account" => $sms["api_account"], "password" => $sms["api_psw"], "msg" => urlencode($msg), "phone" => $mobile, "report" => "true"];
		$url = "http://smssh1.253.com/msg/send/json";
		$result = $this->curlPost($url, $postArr);
		return $result;
	}
	private function curlPost($url, $postFields)
	{
		$postFields = json_encode($postFields);
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json; charset=utf-8"]);
		curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
		curl_setopt($ch, CURLOPT_TIMEOUT, 60);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		$ret = curl_exec($ch);
		if (!$ret) {
			$result = curl_error($ch);
		} else {
			$rsp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
			if (200 != $rsp) {
				$result = "请求状态 " . $rsp . " " . curl_error($ch);
			} else {
				$result = $ret;
			}
		}
		curl_close($ch);
		return $result;
	}
	/**
	 * 积分操作
	 */
	public function scoreAct($uid, $type = 1, $score = 0)
	{
		global $_W;
		$data["uniacid"] = $_W["uniacid"];
		$data["uid"] = $uid;
		$data["type"] = $type;
		$data["score"] = $score;
		$data["createtime"] = time();
		pdo_insert("yzzc_sun_integral_log", $data);
		if ($score > 0) {
			pdo_update("yzzc_sun_user", ["all_integral +=" => $data["score"]], ["id" => $data["uid"]]);
		}
		pdo_update("yzzc_sun_user", ["now_integral +=" => $data["score"]], ["id" => $data["uid"]]);
	}
	public function doMobilefindorder()
	{
		global $_W;
		global $_GPC;
		$time = time();
		$findtime = pdo_get("yzzc_sun_system", ["uniacid" => $_W["uniacid"]]);
		if (!$findtime["findtime"]) {
			pdo_update("yzzc_sun_system", ["findtime" => $time], ["uniacid" => $_W["uniacid"]]);
		} else {
			if ($findtime["findtime"] < $time) {
				$order = count(pdo_fetchall("select id from " . tablename("yzzc_sun_order") . " where uniacid = " . $_W["uniacid"] . " and paytime > " . $findtime["findtime"]));
				pdo_update("yzzc_sun_system", ["findtime" => $time], ["uniacid" => $_W["uniacid"]]);
				echo json_encode($order);
			}
		}
	}
	public function doMobileUpdArea()
	{
		global $_W;
		global $_GPC;
		if ($_GPC["num"]) {
			$data["num"] = $_GPC["num"];
		}
		$res = pdo_update("yzzc_sun_area", $data, ["id" => $_GPC["id"]]);
		if ($res) {
			echo "1";
		} else {
			echo "2";
		}
	}
	public function doMobileUpdAd()
	{
		global $_W;
		global $_GPC;
		if ($_GPC["num"]) {
			$data["orderby"] = $_GPC["num"];
		}
		$res = pdo_update("yzzc_sun_ad", $data, ["id" => $_GPC["id"]]);
		if ($res) {
			echo "1";
		} else {
			echo "2";
		}
	}
	public function doMobileUpdType()
	{
		global $_W;
		global $_GPC;
		if ($_GPC["num"]) {
			$data["num"] = $_GPC["num"];
		}
		if ($_GPC["money"]) {
			$data["money"] = $_GPC["money"];
		}
		$res = pdo_update("yzzc_sun_type", $data, ["id" => $_GPC["id"]]);
		if ($res) {
			echo "1";
		} else {
			echo "2";
		}
	}
	public function doMobileAllDelete()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("yzzc_sun_type2", ["id" => $_GPC["id"]]);
		if ($res) {
			message("删除成功", $this->createWebUrl("type2", []), "success");
		} else {
			message("删除失败", "", "error");
		}
	}
	public function doMobileDeleteType2()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("yzzc_sun_storetype2", ["id" => $_GPC["id"]]);
		if ($res) {
			message("删除成功", $this->createWebUrl("storetype2", []), "success");
		} else {
			message("删除失败", "", "error");
		}
	}
	public function doMobileUpdType2()
	{
		global $_W;
		global $_GPC;
		if ($_GPC["num"]) {
			$data["num"] = $_GPC["num"];
		}
		if ($_GPC["money"]) {
			$data["money"] = $_GPC["money"];
		}
		$res = pdo_update("yzzc_sun_storetype", $data, ["id" => $_GPC["id"]]);
		if ($res) {
			echo "1";
		} else {
			echo "2";
		}
	}
	public function doMobileGetInformationType()
	{
		global $_W;
		global $_GPC;
		$type2 = pdo_getall("yzzc_sun_type2", ["type_id" => $_GPC["id"]]);
		echo json_encode($type2);
	}
	public function doMobileAlldeleteinfo()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("yzzc_sun_information", ["id" => $_GPC["id"]]);
		if ($res) {
			message("删除成功", $this->createWebUrl("information", []), "success");
		} else {
			message("删除失败", "", "error");
		}
	}
	public function doMobileAllUpdateInfo()
	{
		global $_W;
		global $_GPC;
		$arr = $_GPC["arr"];
		if ($arr) {
			foreach ($arr as $v) {
				if ($v["type"] == 1) {
					$res = pdo_update("yzzc_sun_type2", ["state" => 2], ["id" => $v["id"]]);
				}
				if ($v["type"] == 2) {
					$res = pdo_update("yzzc_sun_type2", ["state" => 1], ["id" => $v["id"]]);
				}
			}
		}
	}
	public function doMobileAllUpdateStore()
	{
		global $_W;
		global $_GPC;
		$arr = $_GPC["arr"];
		if ($arr) {
			foreach ($arr as $v) {
				if ($v["type"] == 1) {
					$res = pdo_update("yzzc_sun_storetype2", ["state" => 2], ["id" => $v["id"]]);
				}
				if ($v["type"] == 2) {
					$res = pdo_update("yzzc_sun_storetype2", ["state" => 1], ["id" => $v["id"]]);
				}
			}
		}
	}
	public function doMobileAdoptInfo()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_information", ["state" => 2], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("information", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileRejectInfo()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_information", ["state" => 3], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("information", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileAlldeleteZx()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("yzzc_sun_selected", ["seid" => $_GPC["id"]]);
		if ($res) {
			message("删除成功", $this->createWebUrl("zx", []), "success");
		} else {
			message("删除失败", "", "error");
		}
	}
	public function doMobileAdoptZx()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_zx", ["state" => 2], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("zx", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileRejectZx()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_zx", ["state" => 3], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("zx", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileAlldeleteCar()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("yzzc_sun_car", ["id" => $_GPC["id"]]);
		if ($res) {
			message("删除成功", $this->createWebUrl("zx", []), "success");
		} else {
			message("删除失败", "", "error");
		}
	}
	public function doMobileAdoptCar()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_car", ["state" => 2], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("information", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileRejectCar()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_car", ["state" => 3], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("information", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileAdoptHy()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_yellowstore", ["state" => 2], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("information", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileRejectHy()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_yellowstore", ["state" => 3], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("information", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileDeleteStore()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("yzzc_sun_store", ["id" => $_GPC["id"]]);
		if ($res) {
			message("删除成功", $this->createWebUrl("store", []), "success");
		} else {
			message("删除失败", "", "error");
		}
	}
	public function doMobileAdoptStore()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_store", ["state" => 2], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("information", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileRejectStore()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_store", ["state" => 3], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("information", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileDeleteGoods()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("wyzc_sun_goods", ["id" => $_GPC["id"]]);
		if ($res) {
			message("删除成功", $this->createWebUrl("goods", []), "success");
		} else {
			message("删除失败", "", "error");
		}
	}
	public function doMobileAdoptGoods()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("wyzc_sun_goods", ["status" => 2], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("goods", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileRejectGoods()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("wyzc_sun_goods", ["status" => 3], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("goods", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileDeleteType()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("yzzc_sun_type", ["id" => $_GPC["id"]]);
		if ($res) {
			message("删除成功", $this->createWebUrl("type", []), "success");
		} else {
			message("删除失败", "", "error");
		}
	}
	public function doMobileQyType()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_type", ["state" => 1], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("type", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileJyType()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_type", ["state" => 2], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("type", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileDeleteStoreType()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("yzzc_sun_storetype", ["id" => $_GPC["id"]]);
		if ($res) {
			message("删除成功", $this->createWebUrl("storetype", []), "success");
		} else {
			message("删除失败", "", "error");
		}
	}
	public function doMobileQyStoreType()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_storetype", ["state" => 1], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("storetype", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileJyStoreType()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_storetype", ["state" => 2], ["id" => $_GPC["id"]]);
		if ($res) {
			message("操作成功", $this->createWebUrl("storetype", []), "success");
		} else {
			message("操作失败", "", "error");
		}
	}
	public function doMobileFindUser()
	{
		global $_W;
		global $_GPC;
		$sql = " select id,name from " . tablename("yzzc_sun_user") . " where uniacid={$_W["uniacid"]}  and id not in (select user_id  from" . tablename("yzzc_sun_store") . "where uniacid={$_W["uniacid"]}) and  name like '%{$_GPC["keywords"]}%'";
		$user = pdo_fetchall($sql);
		return json_encode($user);
	}
	public function doMobileFindCity()
	{
		global $_W;
		global $_GPC;
		$sql = " select DISTINCT cityname from " . tablename("yzzc_sun_hotcity") . " where uniacid={$_W["uniacid"]}   and  cityname like '%{$_GPC["keywords"]}%'";
		$city = pdo_fetchall($sql);
		return json_encode($city);
	}
	public function doMobileDeleteZxAssess()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("yzzc_sun_zx_assess", ["id" => $_GPC["id"]]);
		if ($res) {
			message("删除成功", $this->createWebUrl("zxpinglun", []), "success");
		} else {
			message("删除失败", "", "error");
		}
	}
	public function doMobileTypeList()
	{
		global $_W;
		global $_GPC;
		$type = pdo_getall("yzzc_sun_type", ["uniacid" => $_W["uniacid"], "state" => 1], [], "", "num asc");
		$type2 = pdo_getall("yzzc_sun_type2", ["uniacid" => $_W["uniacid"], "state" => 1], [], "", "num asc");
		foreach ($type as $key => $value) {
			$data = $this->getSon($value["id"], $type2);
			$type[$key]["ej"] = $data;
		}
		return json_encode($type);
	}
	public function doMobilePTypeInfo()
	{
		global $_W;
		global $_GPC;
		$res = pdo_get("yzzc_sun_type", ["uniacid" => $_W["uniacid"], "id" => $_GPC["id"]]);
		return json_encode($res);
	}
	public function doMobileSavePType()
	{
		global $_W;
		global $_GPC;
		$data["img"] = $_GPC["img"];
		$data["num"] = $_GPC["num"];
		$data["type_name"] = $_GPC["type_name"];
		$data["money"] = $_GPC["money"];
		$data["state"] = $_GPC["state"];
		$data["uniacid"] = $_W["uniacid"];
		if ($_GPC["id"] == "") {
			$res = pdo_insert("yzzc_sun_type", $data);
		} else {
			$res = pdo_update("yzzc_sun_type", $data, ["id" => $_GPC["id"]]);
		}
		if ($res) {
			echo "1";
		} else {
			echo "2";
		}
	}
	public function doMobileSTypeInfo()
	{
		global $_W;
		global $_GPC;
		$res = pdo_get("yzzc_sun_type2", ["uniacid" => $_W["uniacid"], "id" => $_GPC["id"]]);
		return json_encode($res);
	}
	public function doMobileSaveSType()
	{
		global $_W;
		global $_GPC;
		$data["num"] = $_GPC["num"];
		$data["type_id"] = $_GPC["type_id"];
		$data["name"] = $_GPC["name"];
		$data["state"] = $_GPC["state"];
		$data["uniacid"] = $_W["uniacid"];
		if ($_GPC["id"] == "") {
			$res = pdo_insert("yzzc_sun_type2", $data);
		} else {
			$res = pdo_update("yzzc_sun_type2", $data, ["id" => $_GPC["id"]]);
		}
		if ($res) {
			echo "1";
		} else {
			echo "2";
		}
	}
	public function doMobileQueryTag()
	{
		global $_W;
		global $_GPC;
		$res = pdo_getall("yzzc_sun_label", ["type2_id" => $_GPC["type2_id"]]);
		echo json_encode($res);
	}
	public function doMobileDelTag()
	{
		global $_W;
		global $_GPC;
		$res = pdo_delete("yzzc_sun_label", ["id" => $_GPC["tag_id"]]);
		if ($res) {
			echo "1";
		} else {
			echo "2";
		}
	}
	public function doMobileUpdTag()
	{
		global $_W;
		global $_GPC;
		$res = pdo_update("yzzc_sun_label", ["label_name" => $_GPC["label_name"]], ["id" => $_GPC["tag_id"]]);
		if ($res) {
			echo "1";
		} else {
			echo "2";
		}
	}
}